﻿using System;
using System.Buffers;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RescueApp.Data;
using RescueApp.Model;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;


namespace RescueApp.UI
{
    public partial class ResultDispatch : Form
    {
       
        public static string ConnectingStr = "Server=LAPTOP-1BOQI73G;Database=Rescue;TrustServerCertificate=True;Integrated Security=True;";
        RescueContext db = new RescueContext(ConnectingStr);
        

        public ResultDispatch()
        {
            InitializeComponent();
        }
        public ResultDispatch(RescueContext db)
        {
            InitializeComponent();
            this.db = db;
        }
     

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            string input = textBox1.Text.Trim();

            // 输入转换为整数
            if (!int.TryParse(input, out int searchValue))
            {
                MessageBox.Show("输入空白. 请输入查询内容.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            

            // 查询数据库
            var result = db.RescueDispatches.FirstOrDefault(rd => rd.RescueID == searchValue);
            
           

            if (result != null)
            {
                // 如果找到匹配的记录，显示详细信息
                MessageBox.Show($"救援派遣状态: 已派遣\n"+
                                $"派遣单ID: {result.DispatchID}\n" +
                                $"救援申请ID: {result.RescueID}\n" +
                                $"救援车辆司机: {result.Driver}\n" +
                                $"救援车辆车牌号: {result.LicenseID}\n" +
                                $"到达现场时间: {result.ArrivedTime}\n" +
                                $"故障原因: {result.Cause}\n" +
                                $"救援费用: {result.Cost}",
                                "派遣救援信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
             
                MessageBox.Show("没有找到派遣救援信息，请稍后再试.", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void ResultDispatch_Load(object sender, EventArgs e)
        {

        }
    }
}
